package com.atguigu.spzx.manager.service.impl;


import com.atguigu.spzx.manager.mapper.BrandMapper;
import com.atguigu.spzx.manager.mapper.OrderInfoMapper;
import com.atguigu.spzx.manager.mapper.OrderStaMapper;
import com.atguigu.spzx.manager.service.BrandService;
import com.atguigu.spzx.manager.service.OrderStaService;
import com.atguigu.spzx.model.dto.order.OrderStatisticsDto;
import com.atguigu.spzx.model.entity.order.OrderStatistics;
import com.atguigu.spzx.model.entity.product.Brand;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

// com.atguigu.spzx.manager.service.impl;
@Service
@Transactional
public class OrderStaServiceImpl implements OrderStaService {


    @Autowired
    OrderStaMapper orderStaMapper;

    @Autowired
    OrderInfoMapper orderInfoMapper;

    @Override
    public Map getOrderSta(OrderStatisticsDto orderStatisticsDto) {

        //SELECT order_date,total_amount FROM `order_statistics` ORDER BY order_date
        //每行有两列，对应OrderStatistics对象中的两个属性
        List<OrderStatistics> list = orderStaMapper.selectOrderStaList(orderStatisticsDto);

        //第二种方法 两个lambda表达式
        List<String> dateList = list.stream().map(orderStatistics -> {
            return new DateTime(orderStatistics.getOrderDate()).toString("yyyy-MM-dd");
        }).collect(Collectors.toList());

        List<BigDecimal> amountList = list.stream().map(orderStatistics -> {
            return  orderStatistics.getTotalAmount();
        }).collect(Collectors.toList());

        /*//日期字符串集合
        List<String> dateList = new ArrayList<>();
        List<BigDecimal> amountList = new ArrayList<>();//所有金额使用BigDecimal，精度准确
*/
        /*for (OrderStatistics orderStatistics : list) {
            //order_date订单统计时期
            Date orderDate = orderStatistics.getOrderDate();
            dateList.add(new DateTime(orderDate).toString("yyyy-MM-dd"));
            amountList.add(orderStatistics.getTotalAmount());
        }*/

//        { dateList:[],amountList:[] }
        Map map = new HashMap();
        map.put("dateList",dateList);
        map.put("amountList",amountList);
        return map;
    }


}
